package mvc.model.inventory

import ext.log
import manager.AppManager
import org.json.JSONObject

class GoodsType(val name: String, var number: Int) {
    val row: Int
    val col: Int

    companion object {
        fun withJson(json: JSONObject): GoodsType {
            val name = json.getString("cargoData")
            var number = json.getInt("goodsNum")
            if (AppManager.faultByCargo(name)) {
                number = 0
                log("货道故障 库存清零:$name")
            }
            return GoodsType(name, number)
        }
    }

    init {
        val lists = name.split("-")
        row = lists[0].toInt()
        col = lists[1].toInt()
    }
}